package com.asialjim.wechat.cloud;

import com.asialjim.wechat.pojo.account.WeChatAccount;
import com.asialjim.wechat.wechataccount.WeChatAccountService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <h1><em>ASIAL JIM JAVA DOC</em></h1><hr/>
 * <h2>CLASS DESCRIPTION <i>[ NAME: WeChatAccountCloud ]</i></h2><strong>
 * <p> TODO
 * </strong><p><p><em>Copyright &copy; Asial Jim Co., LTD</em><hr/>
 *
 * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
 * @version 1.0.0
 * @since 2021/4/2   &nbsp;&nbsp; JDK 8
 */
@RestController
@AllArgsConstructor
@RequestMapping("/we_chat/account")
public class WeChatAccountCloud {
    private final WeChatAccountService weChatAccountService;

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: allAccounts ]</i></h3>
     * 获取所有微信公众平台应用账号
     * <p>get all of we-chat application account</p>
     * @return {@link List <  WeChatAccount > accounts}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/23 9:53
     */
    @GetMapping
    public List<WeChatAccount> allAccounts(){
        return weChatAccountService.allAccounts();
    }

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: account ]</i></h3>
     * 通过公众平台appid编号查询公众号账户
     * @param accountId {@link String appid}
     * @return {@link WeChatAccount we chat account}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/23 9:54
     */
    @GetMapping("/appid")
    public WeChatAccount account(String accountId){
        return weChatAccountService.account(accountId);
    }

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: deCacheAllAccount ]</i></h3>
     * 清除缓存
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/23 9:55
     */
    @GetMapping("/cache/delete")
    public void deCacheAllAccount(){
        deCacheAllAccount();
    }

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: findBySubjectId ]</i></h3>
     * 通过微信公众平台应用微信账号获取应用账号
     * @param subjectId {@link String user id for we-chat public application}
     * @return {@link WeChatAccount we chat account}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/23 9:56
     */
    @GetMapping("/subjectid")
    public WeChatAccount findBySubjectId(String subjectId){
        return weChatAccountService.findBySubjectId(subjectId);
    }

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: update ]</i></h3>
     * 修改公众平台应用账号
     * @param account {@link WeChatAccount we chat account}
     * @return {@link Boolean success update}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/23 9:59
     */
    @PostMapping("/update")
    public boolean update(@RequestBody WeChatAccount account){
        return weChatAccountService.update(account);
    }

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: add ]</i></h3>
     * 添加公众平台应用账号
     * @param account {@link WeChatAccount we chat account}
     * @return {@link Boolean success add}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/23 10:00
     */
    @PostMapping("/add")
    public boolean add(@RequestBody WeChatAccount account){
        return weChatAccountService.add(account);
    }

    /**
     * <h3>METHOD DESCRIPTION <i>[ NAME: delete ]</i></h3>
     * 删除公众平台应用账号
     * @param accountId {@link String account app id}
     * @return {@link Boolean success delete}
     * @author Asial Jim &nbsp;&nbsp;<span>Email:asialjim@hotmail.com &nbsp;&nbsp; asialjim@qq.com</span>
     * @since 2021/3/23 10:01
     */
    @GetMapping("/delete")
    public boolean delete(String accountId){
        return weChatAccountService.delete(accountId);
    }
}
